cmake_minimum_required(VERSION 3.11)

include(FetchContent)
# FetchContent_MakeAvailable was not added until CMake 3.14
if(${CMAKE_VERSION} VERSION_LESS 3.14)
  include(add_FetchContent_MakeAvailable.cmake)
endif()

message(STATUS "--- Add dependence glfw")

set(glfw_FILE
    ""
    CACHE STRING "glfw file")
set(glfw_GIT_URL
    https://gitee.com/snow-github-mirrors/glfw.git
    CACHE STRING "glfw git url")
set(glfw_GIT_TAG
    3.3.8
    CACHE STRING "glfw git tag")

set(WITH_APPS OFF)

if(glfw_FILE)
  message(STATUS "--- Use File")
  message(STATUS "\t --- File: ${glfw_FILE}")
  FetchContent_Declare(glfw URL ${glfw_FILE} SOURCE_DIR
                                   ${PROJECT_ROOT}/3rdparty/glfw)
else()
  message(STATUS "--- Use Git")
  message(STATUS "\t --- Repository: ${glfw_GIT_URL}")
  message(STATUS "\t --- Version: ${glfw_GIT_TAG}")
  FetchContent_Declare(
    glfw
    GIT_REPOSITORY ${glfw_GIT_URL}
    GIT_TAG ${glfw_GIT_TAG}
    SOURCE_DIR ${PROJECT_ROOT}/3rdparty/glfw
    GIT_PROGRESS TRUE
    USES_TERMINAL_DOWNLOAD TRUE)
endif()

FetchContent_MakeAvailable(glfw)

message(STATUS "--- Add dependence glfw finished.")
